﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace Common.Converters
{
    /// <summary>
    /// 实现一个数值转换将传入的两个数字乘法运算返回
    /// </summary>
    public class NumConverter : IValueConverter
    {
        /// <summary>
        /// Convert方法
        /// </summary>
        /// <param name="value">      </param>
        /// <param name="targetType"> </param>
        /// <param name="parameter">  </param>
        /// <param name="culture">    </param>
        /// <returns> </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            try
            {
                double param1 = System.Convert.ToDouble(value);
                double param2 = System.Convert.ToDouble(parameter);
                return param1 * param2;
            }
            catch (Exception)
            {
                return 0;
            }
        }

        /// <summary>
        /// ConvertBack方法
        /// </summary>
        /// <param name="value">      </param>
        /// <param name="targetType"> </param>
        /// <param name="parameter">  </param>
        /// <param name="culture">    </param>
        /// <returns> </returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => null;
    }
}